package com.sky.controller.admin;

import com.sky.constant.ShopStatusConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "店铺相关接口")
@RequestMapping("/admin/shop")
@RestController("adminShopController")
public class ShopController {

    @Autowired
    private RedisTemplate redisTemplate;

    @ApiOperation("修改店铺营业状态")
    @PutMapping("/{status}")
    public Result setShopStatus(@PathVariable Integer status) {
        log.info("修改店铺营业状态，{}", status);
        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set(ShopStatusConstant.SHOP_STATUS, status);

        return Result.success();
    }

    @ApiOperation("获得店铺营业状态")
    @GetMapping("/status")
    public Result getShopStatus() {
        Integer status = (Integer) redisTemplate.opsForValue().get(ShopStatusConstant.SHOP_STATUS);
        log.info("获得店铺营业状态,{}", status);
        return Result.success(status);
    }

}
